﻿@using FreightSoft.Classes
@model IEnumerable<FreightSoft.Models.ORDER_LINE>


@{
    ViewBag.Title = "Customer Order: " + ViewBag.ORDER_ID;
}

@{
    FreightSoft.Models.Entities db = new FreightSoft.Models.Entities();
    FreightSoft.Models.CUSTOMER_ORDER order = db.CUSTOMER_ORDER.Find(ViewBag.ORDER_ID);
}


<br />
<br />
<br />


<p style="float:right">

    @if (order.STATUS.Equals("Authorized"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
        <a href="../../CashPayment/Details/@order.ORDER_ID">
            <button type="button" class="btn btn-danger">Receive Cash Payment</button></a> 
        }


        if (User.IsInRole("CUST"))
        {
        
        <a href="../../Credit/Index/@order.ORDER_ID">
            <button type="button" class="btn btn-default">Pay By Credit Card</button></a>  
        
        
        @Html.PayPalButton(true,
    HtmlHelpers.EButtonType.PayNow,
    "notification.msc@gmail.com",
    "MSC Shipment Order",
    @order.ORDER_ID.ToString(),
    (float)@order.ORDER_LINE.Sum(o => o.GROSS_AMOUNT),
    HtmlHelpers.ECurrencyCode.USD,
    "http://localhost:55882/OrderLine/Invoice/" + @order.ORDER_ID,
    "http://localhost:55882/OrderLine/Index/" + @order.ORDER_ID,
    "http://localhost:55882/OrderLine/Index/" + @order.ORDER_ID)
                           }
        
    }

    @if (order.STATUS.Equals("Released"))
    { 
        <a href="../Plan/@order.ORDER_ID"><button type="button" class="btn btn-primary" style="width: 100px">Plan</button></a>
    }

    @if (order.STATUS.Equals("Planned"))
    {
        if (order.ORDER_LINE.Count > 0)
        {
        <a href="../Release/@order.ORDER_ID">
            <button type="button" class="btn btn-success" style="width: 100px">Release</button></a>
        }
    }

    @if (order.STATUS.Equals("Planned") || order.STATUS.Equals("Released") || order.STATUS.Equals("Authorized"))
    {
            <a href="../Cancel/@order.ORDER_ID"><button type="button" class="btn btn-info" style="width: 100px">Cancel</button></a>
    }

    @if (order.STATUS.Equals("Cancelled")){
        <a href="../Plan/@order.ORDER_ID"><button type="button" class="btn btn-info" style="width: 100px">Re-Open</button></a>
    }

    @if (order.STATUS.Equals("Released"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
        <a href="../Authorize/@order.ORDER_ID">
            <button type="button" class="btn btn-warning" style="width: 100px">Authorize</button></a> 
        }
    }

    @if (order.STATUS.Equals("Authorized")){
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
            <a href="../Plan/@order.ORDER_ID"><button type="button" class="btn btn-warning">Revoke Authorization</button></a>
        }
    }

    

</p>



<table class="table">
    <tr>
        <td colspan="4">
            @if (TempData["error"] != null)
            {
                <div class="alert alert-danger">@TempData["error"]</div>
            }
        </td>
    </tr>
    <tr class="active"><td><b>Order No</b></td><td><b>Customer</b></td><td><b>Wanted Delivery Date</b></td><td><b>Delivery Address</b></td></tr>
    <tr class="active"><td>@order.ORDER_ID</td><td>@order.CUSTOMER_ID - @order.CUSTOMER.NAME</td><td>@order.WANTED_DELIVERY_DATE.ToShortDateString()</td><td>@order.DELIVERY_ADDRESS</td></tr>
    <tr class="active"><td><b>Source</b></td><td><b>Destination</b></td><td><b>Authorizor</b></td><td><b>Status</b></td></tr>
    <tr class="active"><td>@order.PORT.PORT_ID - @order.PORT.PORT_NAME</td><td>@order.PORT1.PORT_ID - @order.PORT1.PORT_NAME</td><td>@order.AUTHORIZOR</td><td>@order.STATUS</td></tr>
    <tr class="active"><td></td><td></td><td></td><td></td></tr>
</table>
<b>Order Lines</b><br />

<b> @if (order.STATUS.Equals("Planned")){@Html.ActionLink("Create New", "Create/"+@order.ORDER_ID)}</b>

<table class="table table-striped">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ORDER_ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LINE_ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.PART.PART_DESC)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.QUANTITY)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.NET_AMOUNT)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TAX_AMOUNT)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GROSS_AMOUNT)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ORDER_ID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.LINE_ID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PART.PART_DESC)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.QUANTITY)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NET_AMOUNT)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TAX_AMOUNT)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.GROSS_AMOUNT)
        </td>
        <td> @if (order.STATUS.Equals("Planned")){
            @Html.ActionLink("Edit |", "Edit", new { id=item.ORDER_ID, id2=item.LINE_ID})
            @Html.ActionLink(" Delete", "Delete", new { id = item.ORDER_ID, id2 = item.LINE_ID })
            }
        </td>
    </tr>
}

</table>

<table class="table">
    <tr class="active">
        <td><b>Total Net Amount:</b></td>
        <td><b>Total Tax Amount:</b></td>
        <td><b>Total Gross Amount:</b></td>
    </tr>
    <tr class="active">
        <td>@String.Format("{0:C}", @order.ORDER_LINE.Sum(o=>o.NET_AMOUNT))</td>
        <td>@String.Format("{0:C}", @order.ORDER_LINE.Sum(o=>o.TAX_AMOUNT))</td>
        <td>@String.Format("{0:C}", @order.ORDER_LINE.Sum(o=>o.GROSS_AMOUNT))</td>
    </tr>
</table>
